package com.springcontext.ioc;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Test {

  public class A {
    B b = new B();
  }

  public class B {
    A a = new A();
  }

  /**
   * 循环依赖
   */
  @org.junit.Test
  public void test0() {
    //执行的话 就报错了
    A a = new A();
  }

  @org.junit.Test
  public void test1() {
    AnnotationConfigApplicationContext applicationContext =
            new AnnotationConfigApplicationContext(CompentScanConfig.class);

    AServiceImpl bean = applicationContext.getBean(AServiceImpl.class);
    bean.doWork();
  }

  @org.junit.Test
  public void test2() {
    //通过配置文件 来实现aop
    ClassPathXmlApplicationContext applicationContext =
            new ClassPathXmlApplicationContext("ioc/springcontext.xml");
    AServiceImpl bean = applicationContext.getBean(AServiceImpl.class);
    bean.doWork();
  }


}
